var customerCtrl  = new XFApp.client();
XFApp.client.prototype.customer = {
    successCode : 10000,
    urlItems : {
        submitURL: basePath+"/userCenter/customer/saveInfo",
        activeURL: basePath+"/userCenter/customer/activeEmail"
    },

    formValidate : function(){
        $("#submitForm").validate({
            rules: {
                //userId:"required",
                docketname: "required",
                category: "required",
                biztype: "required",
                industry: "required",
                contactname: "required",
                contactaddress: "required",
                contactemail:     {
                    required:true,
                    email: true
                },
                contactphone:    {
                    required:true,
                    number:true
                }
            },
            messages: {
                docketname: "请填写客户名",
                category: "请选择企业性质",
                biztype: "请选择业务类型",
                industry: "请填写所属行业",
                contactname: "请填写联系人姓名",
                contactaddress: "请填写联系地址",
                contactemail:     {
                    required:"请填写电子邮件",
                    email:"电子邮件格式不正确"
                },
                contactphone:    {
                    required:"请填写手机号码",
                    number:"手机号码格式不正确"
                }
            }
        });
        $("#submitForm").validate();
    },

    updateEmail:function(){
        $("#emailshow").hide();
        $("#contactemail").show();
    },

    activeEmail:function(){
        _this = this;
        var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
        var email = $("#contactemail").val();
        if(!email){
            $("#email-error").html('请填写邮箱地址');
        }
        if(reg.test(email)){
            $.ajax({
                url :_this.urlItems.activeURL,
                data : {email:email},
                dataType : "json",
                type : 'post',
                success : function(data) {
                    if(data.code==_this.successCode){
                        window.webDialogUtil.alert("提示",data.msg);
                    }else{
                        window.webDialogUtil.alert("提示",data.msg);
                    }
                }
            });
        }else{
            $("#email-error").html('邮箱格式错误');
        }

    },

    event : function (){
        _this = this;
        $("#submitBtn").on("click",function(){
/*            if(!$("#userId").val()){
                $("#userId-error").html('请填写用户帐号');
            }*/
            if($("#submitForm").validate().form()){
                    customerCtrl.customer.submit();
            }

        });
        $("#updateBtn").on("click",function(){
            customerCtrl.customer.updateEmail();
        });
        $("#activeBtn").on("click",function(){
            customerCtrl.customer.activeEmail();
        });
        //表单验证
        _this.formValidate();
    },

    submit : function (){
        var entity = {
            docketCode : $("#docketCode").text(),
            docketname : $("#docketname").val()	,
            category : $("#category").val(),
            biztype : $("#biztype").val(),
            industry : $("#industry").val(),
            contactname : $("#contactname").val(),
            contactphone : $("#contactphone").val(),
            fixphone : $("#fixphone").val(),
            contactemail : $("#contactemail").val(),
            contactaddress : $("#contactaddress").val()
        }

        $.ajax({
            url :_this.urlItems.submitURL,
            data : entity,
            dataType : "json",
            type : 'post',
            success : function(data) {
                if(data.code==_this.successCode){
                    window.webDialogUtil.alert("提示",data.msg);
                }else{
                    window.webDialogUtil.alert("提示",data.msg);
                }
            }
        });

    }
}

    $(function(){
        customerCtrl.customer.event();
    });